ARG PHP_VERSION
FROM ${PHP_VERSION}

LABEL maintainer = "Docker PHP By beekimlin@gmail.com"

ARG TZ
ARG PHP_EXTENSIONS
ARG CONTAINER_PACKAGE_URL

ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
ENV COMPOSER_HOME=/tmp/composer


RUN sed -i "s/dl-cdn.alpinelinux.org/${CONTAINER_PACKAGE_URL}/g" /etc/apk/repositories


COPY ./extensions /tmp/extensions

WORKDIR /tmp/extensions

RUN chmod +x install.sh \
    && sh install.sh \
    && rm -rf /tmp/extensions \
    && apk --no-cache add tzdata \
    && cp "/usr/share/zoneinfo/$TZ" /etc/localtime \
    && echo "$TZ" > /etc/timezone \
    # Fix: https://github.com/docker-library/php/issues/240
    && apk add gnu-libiconv libstdc++ --no-cache --repository http://${CONTAINER_PACKAGE_URL}/alpine/edge/community/ --allow-untrusted \
    # Install composer and change it's cache home
    && curl -o /usr/bin/composer https://mirrors.aliyun.com/composer/composer.phar \
    && chmod +x /usr/bin/composer \
    # php image's www-data user uid & gid are 82, change them to 1000 (primary user)
    && apk --no-cache add shadow && usermod -u 1000 www-data && groupmod -g 1000 www-data

WORKDIR /www